package com.shuyun.xxx.guava.practice;

import org.junit.Test;

/**
 * Created by goodb on 2017/5/21.
 */
public class FinalizeTest {
    private static FinalizeTest finalizeTest = null;
    public void isAlive(){
        System.out.println("i am still alive");
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("finalize method executed");
        finalizeTest = this;
    }
    @Test
    public void run() throws Exception{
        finalizeTest = new FinalizeTest();
        finalizeTest = null;
        System.gc();
        Thread.sleep(2000);
        if(finalizeTest != null){
            finalizeTest.isAlive();
        }else{
            System.out.println("i am dead now");
        }
        finalizeTest = null;
        System.gc();
        Thread.sleep(3000);
        if(finalizeTest != null){
            finalizeTest.isAlive();
        }else{
            System.out.println("i am dead now");
        }
    }
}
